// const tbody=document.querySelector('tbody')
// console.log(tbody)
tbody.addEventListener('click', function(e) {
	const target = e.target || e.srcElement
	const tr = target.parentNode.parentNode
	if (Array.from(target.classList).includes('btn-edit')) {	/* Array要大写 */
		tr.classList.add('edit')
		const spans = tr.querySelectorAll('span')
		spans.forEach(span => {
			span.nextElementSibling.value = span.innerHTML/*  */
		})
	} else if (Array.from(target.classList).includes('btn-ok')) {
		const id = tr.getAttribute('data-id')
		const name = tr.querySelector('.input-name').value
		const price = tr.querySelector('.input-price').value
		const num = tr.querySelector('.input-num').value

		utils.fetch('./api/shop/update.php', {id,name,price,num}).then(resp => {
			if (resp.code === 200) {
				tr.classList.remove('edit')
				const spans = tr.querySelectorAll('span')
				spans.forEach(span => {
					span.innerHTML = span.nextElementSibling.value
				})
			}
		})
	}
})
